#! /bin/sh
### BEGIN INIT INFO
# Provides:          mistserver
# Required-Start:    $network
# Default-Start:    2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: MistServer service
# Description:      MistServer - next generation multimedia server
### END INIT INFO

NAME=MistController
DESC="MistServer"
CFG_FILE=/etc/mistserver.conf
LOG_FILE=/var/log/mistserver.log

#
# Function that starts the daemon/service
#
do_start()
{
  echo "Starting $DESC" "$NAME"
  MistController -L $LOG_FILE -c $CFG_FILE &
  RETVAL=$?
  [ $RETVAL = 0 ] && echo "Success" || echo "Failure"
  return $RETVAL
}

#
# Function that stops the daemon/service
#
do_stop()
{
  echo "Stopping $DESC" "$NAME"
  kill `pidof MistController` >/dev/null 2>&1
  RETVAL=$?
  [ $RETVAL = 0 ] && echo "Success" || echo "Failure"
  return $RETVAL
}

do_restart()
{
  do_stop
  sleep 10
  do_start
  return $RETVAL
}

case "$1" in
  start)
    do_start
    ;;
  stop)
    do_stop
    ;;
  restart)
    do_restart
    ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
    exit 3
    ;;
esac

